extends Node2D


@export var ball_scene: PackedScene

@onready var fps_lable = $UI/FPSLable
@onready var time_label = $UI/TimeLabel
@onready var ball_count_label = $UI/BallCountLabel
@onready var ball_statistic_label = $UI/BallStatisticLabel

var total_ball = 0
var time = 0
var ball_statistic = 0

func _on_timer_timeout():
	for i in range(10):
		var random_position = Vector2(randi_range(200, 960), 20)
		var ball_instance = ball_scene.instantiate()
		total_ball += 1
		
		ball_instance.position = random_position
		$BallContainer.add_child(ball_instance)


func _process(delta):
	
	time += delta
	
	fps_lable.text = "FPS: " + str(Engine.get_frames_per_second())
	time_label.text = "Time: " + str(int(time)) + "s"
	ball_count_label.text = "Balls: " + str(total_ball)
	ball_statistic_label.text = "Ball Statistic: " + str($BallContainer.get_child_count())

func _on_area_2d_body_entered(body):
	#print("准备删除: ", body)
	total_ball -= 1
	body.queue_free()
